#include<iostream>
#include<vector>
using namespace std;


template<size_t N>
class bitset
{
public:
  bitset()
  {
    bits.resize(N/8+1,0);
  }
  ~bitset()
  {}
  void flip(size_t pos)
  {
      int i = pos / 8;
      int j = pos % 8;
      bits[i] ^= (1<<j); 
  }
  void set(size_t pos)
  {
      int i = pos / 8;
      int j = pos % 8;
      bits[i] |= (1 << j);
  }
  void reset(size_t pos)
  {
      int i = pos / 8;
      int j = pos % 8;
      bits[i] &= ~(1<<j);
  }
  bool test(size_t pos)
  {
      int i = pos / 8;
      int j = pos % 8;
      return bits[i] &(1 << j);
  }
  bool all()
  {
    int n = bits.size();
    for(int i = 0;i<n-1;i++)
    {
      //全1序列 - > 取反为0
      if(~bits[i] != 0)
      {
        return false;
      }
    }
    //判断最后一个元素前N%8位
    for(int i = 0;i < N % 8 ;i++)
    {
      if(((bits[n-1] >> i)&1) == 0)
        return false;
    }
    return true;
  }
  bool none()
  {
    return !all();
  }
  void Print()
  {
    int n = bits.size();
    cout <<"===================" << endl;
    for(int i = 0;i < n-1;i++)
    {
      if((bits[i] >> i) & 1)
        cout <<"1";
      else 
        cout << "0" ;
    }
    for(int i = 0;i< N % 8;i++)
    {
       if(bits[n-1] &(1 << i) )
         cout << "1";
       else 
         cout << "0";
    }
    cout << endl;
    cout <<"===================" << endl;
  }
  size_t count()
  {
    int cnt = 0;
    for(auto e : bits)
    {
      while(e)
      {
        cnt++;
        e&=(e-1);
      }
    }
    return cnt;
  }
  size_t size()
  {
    return N;
  }
private:
  vector<char> bits;
};
